/************************************************	
 *
 * @Title: FixedBasicDataSource.java
 * @Package com.liuhung.base.dbcp
 * @Description: TODO
 * @author liuhung.com
 * @date 2015年9月20日
 *
 ***********************************************/
 
package com.liuhung.base.dbcp;

import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

/************************************************	
 * @Description:<p>解决DHCP关闭连接时的一个bug:
 * BasicDataSource's method close() doesn't deregister JDBC driver. 
 * This causes permgen memory leaks in web server environments, 
 * during context reloads. For example, using Tomcat 6.0.26 with Spring, 
 * and BasicDataSource declared in Spring context, there is a message printed at web application reload:  
 * SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. 
 * To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
 * </p>
 * ClassName: FixedBasicDataSource 
 * @author liuhung.com
 *
 ***********************************************/
public class FixedBasicDataSource extends BasicDataSource {

	public synchronized void close() throws SQLException {  
        DriverManager.deregisterDriver(DriverManager.getDriver(url));  
        super.close();  
    }  


}
